//package com.es.disped.web.controller.homework;
//
//import java.util.List;
//import java.util.Map;
//import java.util.Optional;
//
//import org.apache.shiro.authz.annotation.Logical;
//import org.apache.shiro.authz.annotation.RequiresPermissions;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.http.HttpStatus;
//import org.springframework.stereotype.Controller;
//import org.springframework.transaction.annotation.Transactional;
//import org.springframework.web.bind.annotation.RequestBody;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RequestMethod;
//import org.springframework.web.bind.annotation.ResponseBody;
//
//import com.es.disped.api.homework.HomeworkService;
//import com.es.disped.common.constant.RecordStatus;
//import com.es.disped.common.model.MsgModel;
//import com.es.disped.common.model.PageModel;
//import com.es.disped.core.controller.BaseController;
//import com.es.disped.dao.model.Homework;
//import com.es.disped.dao.model.HomeworkExample;
//import com.es.disped.dao.model.LessonForeignModel;
//
//import io.swagger.annotations.Api;
//import io.swagger.annotations.ApiOperation;
//import io.swagger.annotations.ApiParam;
//
///**
// * @author Anson<br>
// *	Copyright by EasyShare 2019<br>
// *  
// *  All right reserved<br>
// *
// *  Created on 2019年7月7日 下午12:01:59<br>
// *  名称：HomeworkController.java<br>
// *  描述：作业管理<br>
// */
//@Api(value="作业管理")
//@Controller
//@RequestMapping("/manage/homework")
//public class HomeworkController extends BaseController{
//	
//	private final String LESSON_NAMESPACE="com.es.disped.dao.mapper.lesson.LessonCustomMapper";
//	
//	private final String HOMEWORK_NAMESPACE="com.es.disped.dao.mapper.homework.HomeworkCustomMapper";
//	
//	@Autowired
//	HomeworkService homeworkService;
//
//	@ApiOperation(value="保存作业对象",response=MsgModel.class,httpMethod="POST",notes="保存作业对象")
//	@RequiresPermissions(value={"admin:save","sys:save"},logical=Logical.OR)
//	@Transactional
//	@RequestMapping(value="/save",method=RequestMethod.POST)
//	public @ResponseBody MsgModel save(@RequestBody @ApiParam(name="homework",value="作业对象",required=true) Homework homework)
//	{
//		int count=0;
//		if(Optional.of(homework)
//				.filter(name->homework.getHomeworkName()!=null)
//				.filter(content->homework.getHomeworkContent()!=null)
//				.filter(lId->homework.getLessonId()!=null)
//				.filter(url->homework.getHomeWorkUrl()!=null)
//				.isPresent())
//		{
//			LessonForeignModel foreignModel=this.getService().selectOne(LESSON_NAMESPACE+".getLessonForeignModel", homework.getLessonId());
//			homework.setLessonName(foreignModel.getLessonName());
//			homework.setHomeworkId(getUUID());
//			homework.setHomeworkUpdateTime(this.currentDate("yyyy-MM-dd"));
//			homework.setHomeworkValid(RecordStatus.USEAGE.getValue());
//			count=homeworkService.insertSelective(homework);
//		}
//		return this.resultMsg(count==1?HttpStatus.OK.value():HttpStatus.EXPECTATION_FAILED.value(),
//				count==1?"保存成功":"保存失败", count==1?homework:"");
//	}
//	
//	@ApiOperation(value="更新作业对象",response=MsgModel.class,httpMethod="POST",notes="更新作业对象")
//	@RequiresPermissions(value={"admin:update","sys:update"},logical=Logical.OR)
//	@Transactional
//	@RequestMapping(value="/update",method=RequestMethod.POST)
//	public @ResponseBody MsgModel update(@RequestBody @ApiParam(name="homework",value="作业对象",required=true) Homework homework)
//	{
//		int count=0;
//		if(!this.isNull(homework.getHomeworkId()))
//		{
//			if(!this.isNull(homework.getLessonId()))
//			{
//				LessonForeignModel foreignModel=this.getService().selectOne(LESSON_NAMESPACE+".getLessonForeignModel", homework.getLessonId());
//				homework.setLessonName(foreignModel.getLessonName());
//			}
//			homework.setHomeworkUpdateTime(this.currentDate("yyyy-MM-dd"));
//			count=homeworkService.updateByPrimaryKeySelective(homework);
//		}
//		return this.resultMsg(count==1?HttpStatus.OK.value():HttpStatus.EXPECTATION_FAILED.value(),
//				count==1?"更新成功":"更新失败", count==1?homework:"");
//	}
//	
//	@ApiOperation(value="删除作业对象",response=MsgModel.class,httpMethod="POST",notes="删除作业对象")
//	@RequiresPermissions(value={"admin:delete","sys:delete"},logical=Logical.OR)
//	@RequestMapping(value="/delete",method=RequestMethod.POST)
//	public @ResponseBody MsgModel delete(@RequestBody @ApiParam(name="homework",value="作业对象",required=true) Homework homework)
//	{
//		int count=0;
//		if(!this.isNull(homework.getHomeworkId()))
//		{
//			count=this.getService().delete(HOMEWORK_NAMESPACE+".deleteHomeworkModel", homework.getHomeworkId());
//		}
//		return this.resultMsg(count>=1?HttpStatus.OK.value():HttpStatus.EXPECTATION_FAILED.value(),
//				count>=1?"删除成功":"删除失败", count>=1?homework:"");
//	}
//	
//	@ApiOperation(value="检索作业",response=MsgModel.class,httpMethod="POST",
//			notes="检索作业对象，精确检索：作业ID，课时ID；模糊检索：作业名称，课时名称")
//	@RequiresPermissions(value={"admin:select","sys:select"},logical=Logical.OR)
//	@RequestMapping(value="/list",method=RequestMethod.POST)
//	public @ResponseBody MsgModel list(@RequestBody @ApiParam(name="homework",value="作业对象",required=false) Homework homework)
//	{
//		HomeworkExample listExample=new HomeworkExample();
//		HomeworkExample.Criteria criteria=listExample.createCriteria();
//		if(!this.isNull(homework.getHomeworkId()))
//		{
//			criteria.andHomeworkIdEqualTo(homework.getHomeworkId());
//		}
//		if(!this.isNull(homework.getLessonId()))
//		{
//			criteria.andLessonIdEqualTo(homework.getLessonId());
//		}
//		if(!this.isNull(homework.getHomeworkName()))
//		{
//			criteria.andHomeworkNameLike("%"+homework.getHomeworkName()+"%");
//		}
//		if(!this.isNull(homework.getLessonName()))
//		{
//			criteria.andLessonNameLike("%"+homework.getLessonName()+"%");
//		}
//		List<Homework> list=homeworkService.selectByExample(listExample);
//		return this.resultMsg(!this.isNull(list)?HttpStatus.OK.value():HttpStatus.EXPECTATION_FAILED.value(),
//				!this.isNull(list)?"作业列表加载成功":"作业列表加载失败",!this.isNull(list)?list:"");
//	}
//	
//	@ApiOperation(value="分页加载作业",response=MsgModel.class,httpMethod="POST",notes="分页加载作业，分页参数['offset','limit']")
//	@RequiresPermissions(value={"admin:select","sys:select"},logical=Logical.OR)
//	@RequestMapping(value="/pages",method=RequestMethod.POST)
//	public @ResponseBody MsgModel pages(@RequestBody @ApiParam(name="paramMap",value="分页参数[offset,limit]",required=true) Map<String, Object> paramMap)
//	{
//		HomeworkExample listExample=new HomeworkExample();
//		PageModel<Homework> pageModel=null;
//		if(Optional.of(paramMap)
//				.filter(offset->paramMap.containsKey("offset")!=false)
//				.filter(limit->paramMap.containsKey("limit")!=false)
//				.isPresent())
//		{
//			pageModel=homeworkService.selectByExampleForOffsetPage(listExample,
//					Integer.valueOf(paramMap.get("offset").toString()), Integer.valueOf(paramMap.get("limit").toString()));
//			
//		}
//		return this.resultMsg(!this.isNull(pageModel)?HttpStatus.OK.value():HttpStatus.EXPECTATION_FAILED.value(),
//				!this.isNull(pageModel)?"作业加载成功":"作业加载失败",!this.isNull(pageModel)?pageModel:"");
//	}
//}
